/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.
 */

package jdbcmanager.dbtools;

import java.awt.*;

import jdbcmanager.dbtools.datatypes.*;

/**
 * Represents a DB event.
 * Only the tree and the diagrams fire and receive these events: to notify to each other 
 * what is going on.
 * <p>
 * Everytime that the database is added with a new table or an existing table is dropped, or so,
 * by either DbTree or by a DbDiagram, the tree (if a diagram was the source of the event) and 
 * all the other diagrams hava to be notified, in order to refresh the tree or add or delete 
 * tables in the diagram.  
 * 
 * @author Francisco Morero Peyrona
 */
public class DbChangeEvent extends AWTEvent
{
    public static final int TYPE_ENTITY_CREATED   = 1;
    public static final int TYPE_ENTITY_MODIFIED  = 2;  // Can change its name
    public static final int TYPE_ENTITY_REMOVED   = 3;
    
    private DbEntityDescriptor ded;      // The entity involved in the change
    private DbEntityDescriptor dedOld;   // To reference the old one in the case of modified (name changed)
    
    public DbChangeEvent( Object oSource, int nType, DbEntityDescriptor ded )
    {
        super( oSource, nType );
        
        this.ded = ded;
    }
    
    public DbEntityDescriptor getDbEntityDescriptor()
    {
    	return this.ded;
    }
    
    public DbEntityDescriptor getOldDbEntityDescriptor()
    {
    	return this.dedOld;
    }
    
    public void setOldDbEntityDescriptor( DbEntityDescriptor dedOld )
    {
    	this.dedOld = dedOld;
    }
    
    public String toString()
    {
    	return getClass().getName() +"[ sender= "+ getSource().getClass().getName() +
		                             ", type= "+ getID() +
									 ", ded= "+ this.ded +
									 ", old= "+ this.dedOld;
    }
}